package bb.lanxing.lib.devices.base.converter;

import android.bluetooth.BluetoothGattCharacteristic;
import bb.lanxing.lib.devices.base.CharacteristicConverter;
import bb.lanxing.lib.devices.ble.device.StandardBiketrainerDevice;
import bb.lanxing.lib.devices.core.ble.IGattClient;
import android.util.Log;
import java.util.UUID;
import bb.lanxing.lib.devices.ble.BLEAttributes;

public class BiketrainerConverter implements CharacteristicConverter {
    final static private boolean DebugPower = false;
    final static private String TAG = "BiketrainerConverter";
    static private int intValuePower = 0;

    public void onBiketrainer(int i, int i2, int i3,int i4) {
    }

    @Override
    public final void convert(IGattClient iGattClient, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
        int intValueCumulativeCrankRevolution = 0;
        int intValueLastCrankEventTime = 0;
        if (bluetoothGattCharacteristic.getUuid().equals(UUID.fromString(BLEAttributes.BLE_CYCLING_POWER_CHAR_MEASURE))) {
            if(DebugPower){
                intValuePower = bluetoothGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1);;
            }else {
                intValuePower = bluetoothGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 2);
            }
        }

        if (bluetoothGattCharacteristic.getUuid().equals(UUID.fromString(BLEAttributes.BLE_CADENCE_MEASUREMENT))) {
            intValueCumulativeCrankRevolution = bluetoothGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 1);
            intValueLastCrankEventTime = bluetoothGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 3);
            Log.d(TAG,"intValueCumulativeCrankRevolution is "+ intValueCumulativeCrankRevolution);
            Log.d(TAG,"intValueLastCrankEventTime is "+ intValueLastCrankEventTime);
            Log.d(TAG,"intValuePower is "+ intValuePower);
            onBiketrainer(iGattClient.getType(),intValuePower, intValueCumulativeCrankRevolution,intValueLastCrankEventTime);
        }
    }
}